<?php

defined('BASEPATH') or die('forbidden');

class Vip_Controller Extends Controller {

    private $rolename;
    private $inc;
	private $dbConnt;	//数据库连接
	private $joblist;	//职务列表
	private $professionList;	//职业列表
	private $nameList;
	
    function _init() {//print_r($_SESSION['tttttkk']);
        check_level(50, segment(0), segment(1));
        set_time_limit(0);
        $this->inc = $this->config['inc'];
        //$this->professionList = $this->inc['type_proffessionid'];
        //得到选择的区号
		$areanum = $_SESSION['area_selected_id'];
        if ($areanum == '') 
        {
            echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
            return;
        }
        // db数据库
		$this->dbConnt = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		
		if (false == $this->dbConnt) {
			//内部有提示错误，在此就不提示了
			 //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
		}	
		$this->dbConnt->query("SELECT id, name FROM player");
		while ($n = $this->dbConnt->get_array('default'))
		{
			$this->nameList[$n['id']] = $n['name'];
		}
		//$this->joblist = array('0'=>'会长','1'=>'副会长','2'=>'精英','3'=>'普通');
    }

    function index() {
        $this->view->display("dbplayer/vip/index");
    }

    function flexigrid() {

        list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();

        //$this->db->connect('111.75.194.177','root','654321');
        //200090016 表示 充值	
        $sql = "SELECT COUNT(*) AS num FROM player_vip as A where {$where} ";
        //echo " sql2:$sql ";
        $one = $this->dbConnt->one($sql);
        $total = $one['num'];
        $orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";

        $sql = "SELECT {$colsinfo} FROM player_vip where {$where}   {$orderby} LIMIT {$offset},{$rp}";
        $this->dbConnt->query($sql);
        //$id = 0;
        while ($n = $this->dbConnt->get_array('default')) {
            
        	$n['profession']=$this->professionList[$n['profession']]."(".$n['profession'].")";
        	//$n['profession_type']=$this->professionList[$n['profession_type']]."(".$n['profession_type'].")";
            //$n['indate']=get_datetime($n['indate']);
            $n['playerid']=$this->nameList[$n['playerid']]."(".$n['playerid'].")";
            $rows[] = array('id' => $n['playerid'], 'cell' => $n);
            //$id = $id+1;
        }
        //var_dump($rows);
        $result = array(
            'page' => $page,
            'total' => $total,
            'rows' => $rows
        );

        //$this->dbConnt->free_all();
        echo json_encode($result);
    }

}

?>